package org.xdq.demo.vo;

public class R<T> {

    public static final int CODE_OK = 200;
    public static final int CODE_ERR_BUSI = 500;
    public static final int CODE_ERR_SYS = 530;
    public static final int CODE_ERR_UNLOGINED = 520;


    public static <T> R<T> OK(){
        return new R(CODE_OK,true,null,null);
    }
    public static <T> R<T> OK(T data){
        return new R(CODE_OK,true,null,data);
    }

    public static <T> R<T> OK4Msg(String message){
        return new R(CODE_OK,true,message,null);
    }

    public static <T> R<T> OK(String message,T data){
        return new R(CODE_OK,true,message,data);
    }

    public static <T> R<T> err(int errCode,String message){
        return new R(errCode,false,message,null);
    }

    public static <T> R<T> err(int errCode,String message,T data){
        return new R(errCode,false,message,data);
    }

    private int code;//自定义操作结果的业务代码： 200 成功 ， 500 业务失败，530 系统错误，520 未登录
    private boolean success;//操作是否成功

    private String message;//操作结果的简要描述信息

    private T data;//回送的业务数据

    private R(int code, boolean success, String message, T data) {
        this.code = code;
        this.success = success;
        this.message = message;
        this.data = data;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
